package de.szut.ita13sommerfeld.apacheanalyser.apachelog;

/**
 * 
 * @author Rene Sommerfeld
 *
 */

public class Date {

	private int day;
	private String month;
	private int year;
	private int hour;
	private int minute;
	private int second;
	private String zone;
	
	
	/**
	 * 
	 * @param date is parsed to all specific parts of a Date (DD/Month/YYYY:HH:MM:SS +TIMEZONE)
	 */
	public Date(String date) {
		this.day = Integer.parseInt(date.substring(0, date.indexOf(":")).split("/")[0]);
		this.month = date.substring(0, date.indexOf(":")).split("/")[1];
		this.year = Integer.parseInt(date.substring(0, date.indexOf(":")).split("/")[2]);
		this.hour = Integer.parseInt(date.substring(date.indexOf(":") + 1, date.indexOf(" ")).split(":")[0]);
		this.minute = Integer.parseInt(date.substring(date.indexOf(":") + 1, date.indexOf(" ")).split(":")[1]);
		this.second = Integer.parseInt(date.substring(date.indexOf(":") + 1, date.indexOf(" ")).split(":")[2]);
		this.zone = date.substring(date.indexOf(" ") + 1);
	}

	/**
	 * 
	 * @return returns the day of the date
	 */
	public int getDay() {
		return day;
	}

	/**
	 * 
	 * @param day sets the day of the date
	 */
	public void setDay(int day) {
		this.day = day;
	}

	/**
	 * 
	 * @return returns the month of the date
	 */
	public String getMonth() {
		return month;
	}

	/**
	 * 
	 * @param month sets the month of the date
	 */
	public void setMonth(String month) {
		this.month = month;
	}

	/**
	 * 
	 * @return returns the year of the date
	 */
	public int getYear() {
		return year;
	}

	/**
	 * 
	 * @param year sets the month of the date
	 */
	public void setYear(int year) {
		this.year = year;
	}

	/**
	 * 
	 * @return returns the hour of the date
	 */
	public int getHour() {
		return hour;
	}

	/**
	 * 
	 * @param hour sets the hour of the date
	 */
	public void setHour(int hour) {
		this.hour = hour;
	}

	/**
	 * 
	 * @return returns the minute of the date
	 */
	public int getMinute() {
		return minute;
	}

	/**
	 * 
	 * @param minute sets the minute of the date
	 */
	public void setMinute(int minute) {
		this.minute = minute;
	}

	/**
	 * 
	 * @return returns the second of the date
	 */
	public int getSecond() {
		return second;
	}

	/**
	 * 
	 * @param second sets the second of the date
	 */
	public void setSecond(int second) {
		this.second = second;
	}

	/**
	 * 
	 * @return returns the time zone of the date
	 */
	public String getZone() {
		return zone;
	}

	/**
	 * 
	 * @param zone sets the time zone of the date
	 */
	public void setZone(String zone) {
		this.zone = zone;
	}

	/**
	 * 
	 * @return returns the date in a formatted string
	 */
	public String getDateString() {
		String hourString = (hour < 10) ? "0" + hour : String.valueOf(hour);
		String minuteString = (minute < 10) ? "0" + minute : String.valueOf(minute);
		String secondString = (second < 10) ? "0" + second : String.valueOf(second);
		String formattedDate = String.valueOf(day) + "/" + month + "/" + String.valueOf(year) + " - [" + hourString + ":" + minuteString + ":" + secondString + "]";
		return formattedDate;
	}
}
